<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Blovex4\Controller;
use Blovex4\Logic\AdminLogic;

/**
 * 培训地点控制器
 * @author derek <693472824@qq.com>
 */
class TrainingController extends BaseController {

    /**
     * 获取培训地点列表
     * @author derek <693472824@qq.com>
     */
    public function index () {
        
        $name = I('name');
        
        $where = array();
        
        if(!empty($name)){
        
            $where['name'] = array('like', '%'.(string)$name.'%');
        }
        
        $trainingModel = M('Training');
        $list = $this->lists($trainingModel, $where);
        
        $this->assign('name', $name);
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 增加或修改培训地点
     *
     * @param integer $admin_id
     *            用户ID.
     * @author derek <693472824@qq.com>
     */
    public function editAction() {
        
        $trainingID = I('training_id');
    
        if (!empty($trainingID)) {
    
            $trainingLogic = D('Training', 'Logic');
            $trainingModel = $trainingLogic->getTrainingByID($trainingID);
    
            if (empty($trainingModel)) {
                $this->error('获取数据失败', U('index'));
            } else {
                $this->assign('trainingModel', $trainingModel);
            }
        }
    
        $this->display();
    }
    
    /**
     * 保存培训地点信息
     * @author derek <lixm@my818.com>
     */
    public function saveAction() {
    
        $trainingLogic = D('Training', 'Logic');
        $result = $trainingLogic->saveAction();
    
        if ($result === false) {
            $this->error('操作失败' . $trainingLogic->getError());
        } else {
            $this->success('操作成功', U('index'));
        }
    }

    /**
     * 培训地点删除
     * @author derek <693472824@qq.com>
     */
    public function del() {
        
        $trainingID = I('training_id');
        
        if(empty($trainingID)){
            $this->error('参数错误！');
        }
        
        $trainingLogic = D('Training', 'Logic');
        $result = $trainingLogic->del($trainingID);
        
        if ($result === false) {
            $this->error('参数错误', U('index'));
        } else {
            $this->success('操作成功！', U('index'));
        }
    }
}